package imp.DAO;
import java.io.Serializable;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.transaction.annotation.Transactional;






public class DAOAcceso extends HibernateDaoSupport
implements	DAO {
	      
		  
	@Autowired  
    public void SpringHibernateDao(org.hibernate.SessionFactory sessionFactory) {  
        super.setSessionFactory(sessionFactory);  
    }  
  
    @Transactional  
   public void persist(Object entity) {  
       getHibernateTemplate().saveOrUpdate(entity);  
   }
   @Transactional
   public void delete(Object entity) {
       getHibernateTemplate().delete(entity);
   }
 
   @Transactional  
   public void persist(Object[] entities) {  
       for (int i = 0; i < entities.length; i++) {  
           persist(entities[i]);  
       }  
   }  
 
   @Transactional(readOnly = true)  
   public <T> List<T> find(Class<T> entityClass) {  
       final List<T> entities = getHibernateTemplate().loadAll(entityClass);  
       return entities;  
   }  
 
   @Transactional(readOnly = true)  
   public <T> T load(Class<T> entityClass, Serializable id) {  
       final T entity = (T)getHibernateTemplate().load(entityClass, id);  
       return entity;  
   }  
 
   @Transactional(readOnly = true)  
   public <T> List<T> find(String hql) {  
       final List<T> entities = getHibernateTemplate().find(hql);  
       return entities;  
   }

   @Transactional(readOnly = true)
   public <T> List<T> find(String hql, Object parametro) {
       final List<T> entities = getHibernateTemplate().find(hql, parametro);
       return entities;
   }
   
   @Transactional(readOnly = true)
   public <T> List<T> findByCriteria(DetachedCriteria criteria) {
       final List<T> entities = getHibernateTemplate().findByCriteria(criteria);
       return entities;
   }

    public void flush() {
        getHibernateTemplate().flush();
    }


	     
}  

